window.onload = function(){
	url = "http://custom.ddbuild.cn:8080";
	$('#biming').append(localStorage.username)
	//栏目查询
	$.ajax({
		url: url+'/admin_manage/manager/column_query',
		type:"get",
		dataType:'json',
		success:function(data){
//			console.log(data)			
			res = data.result;
			var html='';
			for(var i=0;i<res.length;i++){
				html+='<li><input class="update_cloum" type="text" readonly="false" value='+res[i].title+' /><button>修改</button><submit id='+res[i].id+' class="update_btn">确认</submit></li>'
			}
			$('#cloum_query').append(html);
		}
	})
	
	//修改栏目名称
    $("#cloum_query").delegate("button", "click", function () {
		$(this).prev('input').css("border","1px solid #ccc")
		$(this).attr("id","update_btn")
	   	$(this).prev('input').removeAttr("readonly")
	   	$(this).next('submit').css("display", "inline-block")
	});
	
	//确认按钮执行修改事件
	$("#cloum_query").delegate("submit", "click", function () {
		$.ajax({
			url: url+'/admin_manage/manager/update_column',
			type:"get",
			dataType:'json',
			data:{"column_id":$(this).eq(0).attr('id'), "title":$(this).prevAll('input').val()},
			success:function(data){
				console.log(data)
				
			}
		})
		$(this).css("display", "none")
		$('.update_cloum').css("border", "none")
		
	})

	
//	栏目查询目地获取ID给创建分类传参
	$.ajax({
		url:url+'/admin_manage/manager/column_query',
		type:"get",
		dataType:'json',
		success:function(data){
//			console.log(data)	
			var cloum_id = [];
			res = data.result;
			var html='';
			for(var i=0;i<res.length;i++){
				html+='<option cloum_id='+res[i].id+'>'+res[i].title+'</option>'
				cloum_id = res[i].id;
			}
			$('#select_cloum').append(html);			
		},
		error:function(){
//			alert(1)
		}
	})
	
	//添加分类
	$('#add_category').click(function(){
		colum_id = $('#select_cloum').find('option:selected').attr('cloum_id')
		$.ajax({
			url:url+'admin_manage/manager/category_adding',
			type:"get",
			dataType:'json',
			data:{
				"title": $("#category_title").val(),
				"subtitle": $("#category_subtitle").val(),
				"meta_keyword": $("#category_subtitle").val(),
				"description": $("#category_key").val(),
				"intro": $("#category_subtitle").val(),
				"colum_id": colum_id
			},
			success:function(data){
//				console.log(data)			
				
			}
		})
	})
	
	//分类查询：
	$.ajax({
		url:url+'/admin_manage/manager/category_query',
		type:"get",
		dataType:'json',
		success:function(data){
//			console.log(data)			
			res = data.result;
			var html='';
			for(var i=0;i<res.length;i++){
				html+='<li><a>'+res[i].title+'</a></li>'
			}
			$('#category_query').append(html);
		}
	})
	
	//	文章录入目地获取ID给创建分类传参
	$.ajax({
		url:url+'/admin_manage/manager/category_query',
		type:"get",
		dataType:'json',
		success:function(data){
//			console.log(data)	
			var cloum_id = [];
			res = data.result;
			var html='';
			for(var i=0;i<res.length;i++){
				html+='<option cloum_id='+res[i].id+'>'+res[i].title+'</option>'
				cloum_id = res[i].id;
			}
			$('#select_catory').append(html);			
		},
		error:function(){
//			alert(1)
		}
	})
	
	
	//文章录入
	$('#add_artical').click(function(){
		user_id = localStorage.id
		page_id = $('#select_catory').find('option:selected').attr('cloum_id')
		$.ajax({
			url:url+'/admin_manage/manager/article_entry',
			type:"get",
			dataType:'json',
			data:{
				"title": $("#page_title").val(),
				"subtitle": $("#page_subtitle").val(),
				"meta_keyword": $("#page_key").val(),
				"description": $("#page_description").val(),
				"intro": $("#page_intro").val(),
				"content": $("#page_content").val(),
				"category_id": page_id,
				"auth": user_id
			},
			success:function(data){
//				console.log(data)			
				
			}
		})
	})
	
//	文章列表获取
	$.ajax({
		url:url+'/admin_manage/manager/get_article_list',
		type:"get",
		dataType:'json',
		success:function(data){
//			console.log(data)			
			res = data.result;
//			cloum = catory.webColumn;
			var html='';
			for(var i=0;i<res.length;i++){
				catory = res[i].webCategory
				cloum = catory.webColumn;
				html+="<tr><td><a href=details.html?id="+res[i].id+" id=artical_page>"+res[i].title+"</a></td><td>"+res[i].auth+"</td><td>"+res[i].create_time+"</td><td>"+res[i].is_del+"</td><td>"+catory.title+"</td><td>"+cloum.title+"</td><td><a href=updates.html?id="+res[i].id+" class='artical_update'><i class='glyphicon glyphicon-pencil'></i> 修改</a><a class='artical_del' id='+res[i].id+'><i class='glyphicon glyphicon-trash'></i> 删除</a></td></tr>"
				
			}
			$('.artical_show').append(html);
		}
	})

//	$('#artical_page').click(function(){
//		
//	})
	$('#update_btn').click(function(){
//		alert(1)
	})
	
}







